# Makefile for the Stjupit Dox RoboCup team
# Matus Horvath, horvathm@decef.elf.stuba.sk
#
# 4th december 2002
#
# Coach added by Peter Trebaticky
# 16th december 2002
#
# try: 
#   make LOUD=y
#   make NDEBUG=y
#   make clean
#   make depclean
################################################################################

PLAYER := PlayerExe
GOALIE := GoalieExe
COACH := CoachExe
OUTPUT := Output

COMMON_SRCS := \
	Common/Interact.cpp Common/Main.cpp Common/World/Vector.cpp \
	Common/Support/Debug.cpp Common/Protocol/CommandGen.cpp \
	Common/Protocol/Parser.cpp Common/Protocol/CharString.cpp \
	Common/Protocol/ServerSocket.cpp Common/Protocol/ParseStrings.cpp \
  Player/Formation.cpp
COMMON_P_AND_G_SRCS := \
	Player/PlayerKernel.cpp Player/PlayerSkills.cpp \
	Player/World/Ball.cpp Player/World/Movable.cpp \
	Player/World/Myself.cpp Player/World/Params.cpp \
	Player/World/Player.cpp Player/World/State.cpp \
	Player/World/Variables.cpp Player/World/World.cpp \
	FCFarmari/Network.cpp FCFarmari/Cell.cpp
EVALUATING_SRCS := \
	Evaluating/EvaluatingPlayerList.cpp Evaluating/EvaluatingPanesMap.cpp \
	Evaluating/EvaluatingPane.cpp Evaluating/EvaluatingPlayer.cpp
PLAYER_SRCS := Player/PlayerTactics.cpp
GOALIE_SRCS := Player/GoalieTactics.cpp
COACH_SRCS := Coach/CoachKernel.cpp Coach/World/CoachMemory.cpp \
	Coach/CoachSynchronization.cpp Coach/CoachAnalyser.cpp

PLAYER_CFLAGS =
GOALIE_CFLAGS = -DGOALIE
COACH_CFLAGS = -DCOACH

CXX         = g++
LD          = g++

CPPFLAGS    +=
CFLAGS      += -O2 -I.
CXXFLAGS    +=
LDFLAGS     += -Wall -lm

ifdef NDEBUG

CPPFLAGS    +=
CFLAGS      += -g -DDEBUG 
CXXFLAGS    +=
LDFLAGS     +=

else

CPPFLAGS    +=
CFLAGS      +=
CXXFLAGS    +=
LDFLAGS     +=

endif

################################################################################

PLAYER_OBJS := $(sort $(addprefix $(OUTPUT)/$(PLAYER)/, $(addsuffix .o, $(basename $(COMMON_SRCS) $(COMMON_P_AND_G_SRCS) $(EVALUATING_SRCS) $(PLAYER_SRCS)))))
GOALIE_OBJS := $(sort $(addprefix $(OUTPUT)/$(GOALIE)/, $(addsuffix .o, $(basename $(COMMON_SRCS) $(COMMON_P_AND_G_SRCS) $(EVALUATING_SRCS) $(GOALIE_SRCS)))))
COACH_OBJS := $(sort $(addprefix $(OUTPUT)/$(COACH)/, $(addsuffix .o, $(basename $(COMMON_SRCS) $(COACH_SRCS)))))

$(OUTPUT)/$(PLAYER)/%.o: %.cpp
	echo -n "$(PLAYER): Compiling $<... "
	mkdir -p $(dir $@)
	$(CXX) -c $(CPPFLAGS) $(CFLAGS) $(CXXFLAGS) $(PLAYER_CFLAGS) -o $@ $<
	echo "done"

$(OUTPUT)/$(GOALIE)/%.o: %.cpp
	echo -n "$(GOALIE): Compiling $<... "
	mkdir -p $(dir $@)
	$(CXX) -c $(CPPFLAGS) $(CFLAGS) $(CXXFLAGS) $(GOALIE_CFLAGS) -o $@ $<
	echo "done"

$(OUTPUT)/$(COACH)/%.o: %.cpp
	echo -n "$(COACH): Compiling $<... "
	mkdir -p $(dir $@)
	$(CXX) -c $(CPPFLAGS) $(CFLAGS) $(CXXFLAGS) $(COACH_CFLAGS) -o $@ $<
	echo "done"

.PHONY: all clean depclean

all: $(OUTPUT)/$(PLAYER)/$(PLAYER) $(OUTPUT)/$(GOALIE)/$(GOALIE) $(OUTPUT)/$(COACH)/$(COACH)

$(OUTPUT)/$(PLAYER)/$(PLAYER): $(PLAYER_OBJS)
	echo -n "$(PLAYER): Linking $@... "
	mkdir -p $(dir $@)
	$(LD) $(CFLAGS) $(CXXFLAGS) $(PLAYER_CFLAGS) -o $@ $^ $(LDFLAGS)
	echo "done"
	
$(OUTPUT)/$(GOALIE)/$(GOALIE): $(GOALIE_OBJS)
	echo -n "$(GOALIE): Linking $@... "
	mkdir -p $(dir $@)
	$(LD) $(CFLAGS) $(CXXFLAGS) $(GOALIE_CFLAGS) -o $@ $^ $(LDFLAGS)
	echo "done"
	
$(OUTPUT)/$(COACH)/$(COACH): $(COACH_OBJS)
	echo -n "$(COACH): Linking $@... "
	mkdir -p $(dir $@)
	$(LD) $(CFLAGS) $(CXXFLAGS) $(COACH_CFLAGS) -o $@ $^ $(LDFLAGS)
	echo "done"
	
clean:
	echo -n "Cleaning up... "
	-rm -rf $(OUTPUT)
	echo done

ifndef LOUD
.SILENT:
endif
